CREATE TABLE [SpPrep] (
	IDP int NOT NULL,
	FAMIO nvarchar(50) NOT NULL,
  CONSTRAINT [PK_SPPREP] PRIMARY KEY CLUSTERED
  (
  [IDP] ASC
  ) WITH (IGNORE_DUP_KEY = OFF)

)
GO
CREATE TABLE [SpPred] (
	IDD int NOT NULL,
	NAIM nvarchar(50) NOT NULL,
  CONSTRAINT [PK_SPPRED] PRIMARY KEY CLUSTERED
  (
  [IDD] ASC
  ) WITH (IGNORE_DUP_KEY = OFF)

)
GO
CREATE TABLE [SPGRUP] (
	IDG int NOT NULL,
	KURS int NOT NULL,
	NAIM nvarchar(50) NOT NULL,
  CONSTRAINT [PK_SPGRUP] PRIMARY KEY CLUSTERED
  (
  [IDG] ASC
  ) WITH (IGNORE_DUP_KEY = OFF)

)
GO
CREATE TABLE [SPNAGR] (
	IDN int NOT NULL,
	IDP int NOT NULL,
	IDG int NOT NULL,
	IDD int NOT NULL,
	CHSEM int NOT NULL,
  CONSTRAINT [PK_SPNAGR] PRIMARY KEY CLUSTERED
  (
  [IDN] ASC
  ) WITH (IGNORE_DUP_KEY = OFF)

)
GO
CREATE TABLE [UROKI] (
	ID int NOT NULL,
	DAT datetime NOT NULL,
	IDD int NOT NULL,
	IDP int NOT NULL,
	IDG int NOT NULL,
  CONSTRAINT [PK_UROKI] PRIMARY KEY CLUSTERED
  (
  [ID] ASC
  ) WITH (IGNORE_DUP_KEY = OFF)

)
GO



ALTER TABLE [SPNAGR] WITH CHECK ADD CONSTRAINT [SPNAGR_fk0] FOREIGN KEY ([IDP]) REFERENCES [SpPrep]([IDP])
ON UPDATE CASCADE
GO
ALTER TABLE [SPNAGR] CHECK CONSTRAINT [SPNAGR_fk0]
GO
ALTER TABLE [SPNAGR] WITH CHECK ADD CONSTRAINT [SPNAGR_fk1] FOREIGN KEY ([IDG]) REFERENCES [SPGRUP]([IDG])
ON UPDATE CASCADE
GO
ALTER TABLE [SPNAGR] CHECK CONSTRAINT [SPNAGR_fk1]
GO
ALTER TABLE [SPNAGR] WITH CHECK ADD CONSTRAINT [SPNAGR_fk2] FOREIGN KEY ([IDD]) REFERENCES [SpPred]([IDD])
ON UPDATE CASCADE
GO
ALTER TABLE [SPNAGR] CHECK CONSTRAINT [SPNAGR_fk2]
GO

ALTER TABLE [UROKI] WITH CHECK ADD CONSTRAINT [UROKI_fk0] FOREIGN KEY ([IDD]) REFERENCES [SpPred]([IDD])
ON UPDATE CASCADE
GO
ALTER TABLE [UROKI] CHECK CONSTRAINT [UROKI_fk0]
GO
ALTER TABLE [UROKI] WITH CHECK ADD CONSTRAINT [UROKI_fk1] FOREIGN KEY ([IDP]) REFERENCES [SpPrep]([IDP])
ON UPDATE CASCADE
GO
ALTER TABLE [UROKI] CHECK CONSTRAINT [UROKI_fk1]
GO
ALTER TABLE [UROKI] WITH CHECK ADD CONSTRAINT [UROKI_fk2] FOREIGN KEY ([IDG]) REFERENCES [SPGRUP]([IDG])
ON UPDATE CASCADE
GO
ALTER TABLE [UROKI] CHECK CONSTRAINT [UROKI_fk2]
GO

